package com.googlecode.gwtbb.client.only.widget.form.entry;

import com.google.gwt.user.client.ui.CheckBox;
import com.google.gwt.user.client.ui.Widget;
import com.googlecode.gwtbb.client.only.widget.form.GetBooleanValue;
import com.googlecode.gwtbb.client.shared.validation.FieldId;

/**
 * @author Abraham Grief
 * @version $Id$
 * @since Apr 30, 2008
 */
public class SingleCheckBoxFormEntry extends SingleCellFormEntry implements GetBooleanValue {
	private CheckBox entryCheckBox;
	private boolean defaultBooleanValue;

	public SingleCheckBoxFormEntry(FieldId fieldId, boolean defaultBooleanValue, int row, int col, CheckBox entryCheckBox) {
		this.fieldId = fieldId;
		this.row = row;
		this.col = col;
		this.entryCheckBox = entryCheckBox;
		this.defaultBooleanValue = defaultBooleanValue;
		clearValue();
	}

	public boolean getDefaultBooleanValue() {
		return defaultBooleanValue;
	}

	public void setDefaultBooleanValue(boolean defaultBooleanValue) {
		this.defaultBooleanValue = defaultBooleanValue;
	}

	public CheckBox getEntryCheckBox() {
		return entryCheckBox;
	}

	public void clearValue() {
		entryCheckBox.setChecked(defaultBooleanValue);
	}

	public boolean getBooleanValue() {
		return entryCheckBox.isChecked();
	}

	public String getDefaultValue() {
		return String.valueOf(getDefaultBooleanValue());
	}

	public Widget getEntryWidget() {
		return entryCheckBox;
	}

	public String getValue() {
		return String.valueOf(getBooleanValue());
	}

	public void setBooleanValue(boolean booleanValue) {
		entryCheckBox.setChecked(booleanValue);
	}

	public void setDefaultValue(String defaultValue) {
		this.defaultBooleanValue = Boolean.valueOf(defaultValue).booleanValue();
	}

	public void setValue(String value) {
		entryCheckBox.setChecked(Boolean.valueOf(value).booleanValue());
	}
}
